<!DOCTYPE html>
<html lang="zh_Ch">
    <head>
  <!-- 元数据 -->
  <meta charset="utf-8">
  
  
  <title>在线图片转svg附源码 | Blog</title>
  
  <meta name="author" content="Sun Liusen" />
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="robots" content="index,follow" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <meta name="format-detection" content="telphone=no, email=no" />
  
    <meta name="keywords" content="工具" />
  
  <meta name="description" content="const base64ToFile &#x3D; () &#x3D;&gt;{     let base64 &#x3D; &#96;data:text&#x2F;html;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBsYW5nPSJlbiI+DQoJPGhlYWQ+DQoJCTxtZXRhIGNoYXJzZXQ9IlVURi04Ij4NCgkJPHRpdGxlPuaXoDwvdGl0bGU+DQoJCTxzdHl">
<meta property="og:type" content="article">
<meta property="og:title" content="在线图片转svg附源码">
<meta property="og:url" content="https://slsandxr.top/2023/06/06/JS/%E5%9C%A8%E7%BA%BF%E5%9B%BE%E7%89%87%E8%BD%ACsvg%E9%99%84%E6%BA%90%E7%A0%81/index.html">
<meta property="og:site_name" content="Blog">
<meta property="og:description" content="const base64ToFile &#x3D; () &#x3D;&gt;{     let base64 &#x3D; &#96;data:text&#x2F;html;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBsYW5nPSJlbiI+DQoJPGhlYWQ+DQoJCTxtZXRhIGNoYXJzZXQ9IlVURi04Ij4NCgkJPHRpdGxlPuaXoDwvdGl0bGU+DQoJCTxzdHl">
<meta property="og:locale" content="zh_CH">
<meta property="article:published_time" content="2023-06-06T08:43:26.000Z">
<meta property="article:modified_time" content="2024-12-16T11:07:04.234Z">
<meta property="article:author" content="Sun Liusen">
<meta property="article:tag" content="工具">
<meta name="twitter:card" content="summary">
  
  <!-- 站点验证相关 -->
  
    
    
    
  
  <!-- 样式表文件 -->
  <link rel="stylesheet" id="kratos-css" href="/css/kratosr.min.css" media="all"></script>
  
    <link rel="stylesheet" id="darkmode-css" href="/css/kr-color-dark.min.css" media="(prefers-color-scheme: dark)"></script>
    <script src="/js/kr-dark.min.js"></script>
  
  
    <link rel="stylesheet" id="highlight-css" href="/css/highlight/night-eighties.min.css" media="all"></script>
  
  <link rel="stylesheet" id="fontawe-css" href="/vendors/font-awesome@4.7.0/css/font-awesome.min.css" media="all"></script>
  <link rel="stylesheet" id="nprogress-css" href="/vendors/nprogress@0.2.0/nprogress.css" media="all"></script>
  
  
    <link rel="stylesheet" href="/vendors/aplayer@1.10.1/dist/APlayer.min.css"></script>
  
  
    <link rel="stylesheet" href="/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css"></script>
  
  <!-- 不得不预先加载的一些JS文件 -->
  <script src="/vendors/jquery@3.6.0/dist/jquery.min.js"></script>
  
    <script src="/vendors/qrcode_js@1.0.0/qrcode.min.js"></script>
  
  
  <style>
    
    
  </style>
  
<meta name="generator" content="Hexo 6.3.0"></head>


    <body class="custom-background">
        <div id="kratos-wrapper">
    <div id="kratos-page">
        <div id="kratos-header">
            <header id="kratos-desktop-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="nav-header">
                        <nav id="kratos-menu-wrap">
                            <ul id="kratos-primary-menu" class="sf-menu">
                                
                                    
                                    
                                
                            </ul>
                        </nav>
                    </div>
                </div>
            </header>
            <header id="kratos-mobile-topnav" class="kratos-topnav">
                <div class="container">
                    <div class="color-logo"><a href="/">Blog</a></div>
                    <div class="nav-toggle">
                        <a class="kratos-nav-toggle js-kratos-nav-toggle">
                            <i></i>
                        </a>
                    </div>
                </div>
            </header>
        </div>
        <div class="kratos-start kratos-hero-2">
            <!-- <div class="kratos-overlay"></div> -->
            <div class="kratos-cover kratos-cover-2 text-center">
                <div class="desc desc2 animate-box">
                    <a href="/">
                        <h2>Blog</h2> <br />
                        <span></span>
                    </a>
                </div>
            </div>
        </div>

        <div id="kratos-blog-post">
            <div class="container">
                <div id="main" class="row">
                    

        

            <section class="col-md-8">

        

            <article itemscope itemtype="https://schema.org/Article">
    
    <link itemprop="mainEntityOfPage" href="https://slsandxr.top/2023/06/06/JS/%E5%9C%A8%E7%BA%BF%E5%9B%BE%E7%89%87%E8%BD%ACsvg%E9%99%84%E6%BA%90%E7%A0%81/">
    <div class="kratos-hentry kratos-post-inner clearfix">
        <header class="kratos-entry-header">
            
                <h1 class="kratos-entry-title text-center" itemprop="name headline">在线图片转svg附源码</h1>
            
            
            <ul class="kratos-post-meta text-center">
                <li><time datetime="2023-06-06T08:43:26.000Z" itemprop="datePublished"><i class="fa fa-calendar"></i> 2023-06-06</time></li>
                <li itemprop="author" itemscope itemtype="https://schema.org/Person">
                    <i class="fa fa-user"></i> 作者 <span itemprop="name">Sun Liusen</span>
                </li>
                
                    <li>
                        <i class="fa fa-edit"></i> 
                        
                        
                            ~9.00K
                        
                        字
                    </li>
                
                
            </ul>
        </header>
        <div class="kratos-post-content">
            
            <div id="expire-alert" class="alert alert-warning hidden" role="alert">
                <div class="icon"><i class="fa fa-warning"></i></div>
                <div class="text"><p>本文最后编辑于 <time datetime="1734347224234"></time> 前，其中的内容可能需要更新。</p></div>
            </div>
            
            
            
            <hr />
            <div itemprop="articleBody"><script>
const base64ToFile = () =>{
    let base64 = `data:text/html;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBsYW5nPSJlbiI+DQoJPGhlYWQ+DQoJCTxtZXRhIGNoYXJzZXQ9IlVURi04Ij4NCgkJPHRpdGxlPuaXoDwvdGl0bGU+DQoJCTxzdHlsZT4NCgkJCS5zZWxlY3Rvci1pbWFnZXMgew0KCQkJCWRpc3BsYXk6IGZsZXg7DQoJCQkJZmxleC13cmFwOiB3cmFwOw0KCQkJfQ0KDQoJCQkuc2VsZWN0b3ItaW1hZ2VzIGltZyB7DQoJCQkJbWFyZ2luLXJpZ2h0OiA4cHg7DQoJCQl9DQoJCQkud3JhcHBhcnsNCgkJCQl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dmVyc2lvbj0iMS4xIiBmaWxlX25hbWU9IiR7aXRlbS5maWxlX25hbWV9IiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJCQkJd2lkdGg9IiR7d2lkdGh9cHgiIGhlaWdodD0iJHtoZWlnaHR9cHgiDQoJCQkJdmlld0JveD0iMCAwICR7d2lkdGh9ICR7aGVpZ2h0fSIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgJHt3aWR0aH0gJHtoZWlnaHR9IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCgkJCQkgICAgPGltYWdlIGlkPSJpbWFnZTAiIHdpZHRoPSIke3dpZHRofSIgaGVpZ2h0PSIke2hlaWdodH0iIHg9IjAiIHk9IjAiIGhyZWY9IiR7ZGF0YVVSTH0iPjwvaW1hZ2U+DQoJCQkJPC9zdmc+YDsNCgkJCQkvL+WKoOWFpeWIsGRvbQ0KCQkJCXNob3dTdmdzLmlubmVySFRNTCA9IGAke3Nob3dTdmdzLmlubmVySFRNTH0gJHtzdmdTdHJpbmd9YDsNCgkJCQlzZWxlY3RvckltYWdlcy5hcHBlbmRDaGlsZChpdGVtKTsNCgkJCX0pOw0KCQl9IGNhdGNoIChlKSB7DQoJCQljb25zb2xlLmVycm9yKGUpOw0KCQkJYWxlcnQoJ+WHuumUmScpDQoJCX0NCgl9DQo8L3NjcmlwdD4K`
     let filename = 'text';
     let contentType = 'text/html';
     var arr = base64.split(',')  //去掉base64格式图片的头部
     var bstr = atob(arr[1])   //atob()方法将数据解码
     var leng = bstr.length
     var u8arr = new Uint8Array(leng)
     while(leng--){
        u8arr[leng] =  bstr.charCodeAt(leng) //返回指定位置的字符的 Unicode 编码
     }
     return new File([u8arr], filename, {type:contentType}) 
 }
    let bolb = base64ToFile()
    let articleBody = document.querySelector("[itemprop='articleBody']");
    articleBody.innerHTML = `<iframe src="${URL.createObjectURL(bolb)}" style="width:680px;height:600px;" frameborder="0"></iframe> ${articleBody.innerHTML}`
</script>

<h2 id="源码"><a href="#源码" class="headerlink" title="源码"></a>源码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=&quot;en&quot;&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">		&lt;title&gt;无&lt;/title&gt;</span><br><span class="line">		&lt;style&gt;</span><br><span class="line">			.selector-images &#123;</span><br><span class="line">				display: flex;</span><br><span class="line">				flex-wrap: wrap;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.selector-images img &#123;</span><br><span class="line">				margin-right: 8px;</span><br><span class="line">			&#125;</span><br><span class="line">			.wrappar&#123;</span><br><span class="line">				width: 1100px;</span><br><span class="line">				margin: 0 auto;</span><br><span class="line">				margin-top: 20px;</span><br><span class="line">				border: 1px solid #cccccc;</span><br><span class="line">				padding: 10px;</span><br><span class="line">				border-radius: 10px;</span><br><span class="line">				box-sizing: border-box;</span><br><span class="line">			&#125;</span><br><span class="line">		&lt;/style&gt;</span><br><span class="line">	&lt;/head&gt;</span><br><span class="line">	&lt;body&gt;</span><br><span class="line">		&lt;div class=&quot;wrappar&quot;&gt;</span><br><span class="line">			&lt;p style=&quot;color:red;font-size: 14px;&quot;&gt;请允许多个文件下载，没有大小限制，只要是图片就能给你转。&lt;/p&gt;</span><br><span class="line">			&lt;p&gt;图片地址： &lt;input type=&quot;file&quot; onchange=&quot;handleChange(this)&quot; accept=&quot;image/*&quot; multiple /&gt; &lt;/p&gt;</span><br><span class="line">			&lt;div class=&quot;selector-images&quot;&gt;&lt;/div&gt;</span><br><span class="line">			&lt;p&gt;转换为svg：&lt;button type=&quot;button&quot; onclick=&quot;handleDownload(this)&quot;&gt;下载svg&lt;/button&gt;&lt;/p&gt;</span><br><span class="line">			&lt;div class=&quot;show-svgs&quot;&gt;&lt;/div&gt;</span><br><span class="line">		&lt;/div&gt;</span><br><span class="line">	&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">	//下载功能</span><br><span class="line">	function handleDownload(arg) &#123;</span><br><span class="line">		let downloadSvg = [...document.getElementsByClassName(&#x27;download-svg&#x27;)];</span><br><span class="line">		if(!downloadSvg.length) return alert(&#x27;请选择图片&#x27;)</span><br><span class="line">		downloadSvg.forEach(item =&gt; &#123;</span><br><span class="line">			let fileName = item.getAttribute(&#x27;file_name&#x27;);</span><br><span class="line">			let fileNameText = fileName.replace(/\.[^.]*$/, &#x27;.svg&#x27;);</span><br><span class="line">			let blob = new Blob([item.outerHTML], &#123;</span><br><span class="line">				type: &#x27;image/svg&#x27;</span><br><span class="line">			&#125;);</span><br><span class="line">			let href = window.URL.createObjectURL(blob);</span><br><span class="line">			let a = document.createElement(&#x27;a&#x27;);</span><br><span class="line">			a.href = href;</span><br><span class="line">			a.download = fileNameText; //设置下载svg的名称</span><br><span class="line">			document.body.appendChild(a);</span><br><span class="line">			a.click();</span><br><span class="line">			document.body.removeChild(a);</span><br><span class="line">			URL.revokeObjectURL(href);</span><br><span class="line">		&#125;);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	async function handleChange(e) &#123;</span><br><span class="line">		try &#123;</span><br><span class="line">			let files = [...e.files];</span><br><span class="line">			let arr = [];</span><br><span class="line">			let selectorImages = document.getElementsByClassName(&#x27;selector-images&#x27;)[0];</span><br><span class="line">			let showSvgs = document.getElementsByClassName(&#x27;show-svgs&#x27;)[0];</span><br><span class="line">			selectorImages.innerHTML = &#x27;&#x27;;</span><br><span class="line">			showSvgs.innerHTML = &#x27;&#x27;;</span><br><span class="line">			files.forEach(item =&gt; &#123;</span><br><span class="line">				arr.push(new Promise((reslove, reject) =&gt; &#123;</span><br><span class="line">					let img = document.createElement(&#x27;img&#x27;);</span><br><span class="line">					img.src = URL.createObjectURL(item);</span><br><span class="line">					img.file_name = item.name;</span><br><span class="line">					img.file_type = item.type;</span><br><span class="line">					img.onload = () =&gt; reslove(img);</span><br><span class="line">				&#125;))</span><br><span class="line">			&#125;)</span><br><span class="line">			let res = await Promise.all(arr);</span><br><span class="line">			res.forEach(item =&gt; &#123; //渲染</span><br><span class="line">				let canvas = document.createElement(&quot;canvas&quot;);</span><br><span class="line">				let ctx = canvas.getContext(&quot;2d&quot;);</span><br><span class="line">				let width = item.width;</span><br><span class="line">				let height = item.height;</span><br><span class="line">				canvas.height = height;</span><br><span class="line">				canvas.width = width;</span><br><span class="line">				ctx.drawImage(item, 0, 0, width, height);</span><br><span class="line">				let dataURL = canvas.toDataURL();</span><br><span class="line">				let svgString = `&lt;svg class=&quot;download-svg&quot; version=&quot;1.1&quot; file_name=&quot;$&#123;item.file_name&#125;&quot; id=&quot;Layer_1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot; x=&quot;0px&quot; y=&quot;0px&quot;</span><br><span class="line">				width=&quot;$&#123;width&#125;px&quot; height=&quot;$&#123;height&#125;px&quot;</span><br><span class="line">				viewBox=&quot;0 0 $&#123;width&#125; $&#123;height&#125;&quot; enable-background=&quot;new 0 0 $&#123;width&#125; $&#123;height&#125;&quot; xml:space=&quot;preserve&quot;&gt;</span><br><span class="line">				    &lt;image id=&quot;image0&quot; width=&quot;$&#123;width&#125;&quot; height=&quot;$&#123;height&#125;&quot; x=&quot;0&quot; y=&quot;0&quot; href=&quot;$&#123;dataURL&#125;&quot;&gt;&lt;/image&gt;</span><br><span class="line">				&lt;/svg&gt;`;</span><br><span class="line">				//加入到dom</span><br><span class="line">				showSvgs.innerHTML = `$&#123;showSvgs.innerHTML&#125; $&#123;svgString&#125;`;</span><br><span class="line">				selectorImages.appendChild(item);</span><br><span class="line">			&#125;);</span><br><span class="line">		&#125; catch (e) &#123;</span><br><span class="line">			console.error(e);</span><br><span class="line">			alert(&#x27;出错&#x27;)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</div>
        </div>
        
            <div class="kratos-copyright text-center clearfix">
                <h5 itemprop="copyrightNotice">本作品采用 <a rel="license nofollow" target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/">知识共享署名-相同方式共享 4.0 国际许可协议</a> 进行许可</h5>
            </div>
        
        <footer class="kratos-entry-footer clearfix">
            
                <div class="post-like-donate text-center clearfix" id="post-like-donate">
                
                
                    <a class="share" href="javascript:;"><i class="fa fa-share-alt"></i> 分享</a>
                    <div class="share-wrap" style="display: none;">
    <div class="share-group">
        <a href="javascript:;" class="share-plain qq" onclick="share('qq');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-qq"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain qzone" onclick="share('qzone');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-star"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weixin pop style-plain" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weixin"></i>
            </div>
            <div class="share-int">
                <div class="qrcode" id="wechat-qr"></div>
                <p>打开微信“扫一扫”，打开网页后点击屏幕右上角分享按钮</p>
            </div>
        </a>
        <a href="javascript:;" class="share-plain weibo" onclick="share('weibo');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-weibo"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain facebook style-plain" onclick="share('facebook');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-facebook"></i>
            </div>
        </a>
        <a href="javascript:;" class="share-plain twitter style-plain" onclick="share('twitter');" rel="nofollow">
            <div class="icon-wrap">
                <i class="fa fa-twitter"></i>
            </div>
        </a>
    </div>
    <script type="text/javascript">
        $(()=>{
            new QRCode("wechat-qr", {
                text: "https://slsandxr.top/2023/06/06/JS/%E5%9C%A8%E7%BA%BF%E5%9B%BE%E7%89%87%E8%BD%ACsvg%E9%99%84%E6%BA%90%E7%A0%81/",
                width: 150,
                height: 150,
                correctLevel : QRCode.CorrectLevel.H
            });
        });
        function share(dest) {
            const qqBase        = "https://connect.qq.com/widget/shareqq/index.html?";
            const weiboBase     = "https://service.weibo.com/share/share.php?";
            const qzoneBase     = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?";
            const facebookBase  = "https://www.facebook.com/sharer/sharer.php?";
            const twitterBase   = "https://twitter.com/intent/tweet?";
            const hostUrl       = "https://slsandxr.top/2023/06/06/JS/%E5%9C%A8%E7%BA%BF%E5%9B%BE%E7%89%87%E8%BD%ACsvg%E9%99%84%E6%BA%90%E7%A0%81/";
            const title         = "「在线图片转svg附源码」";
            const excerpt       = `
const base64ToFile = () =>{
    let base64 = \`data:text/html;base64,PCFET0NUWVBFIGh0bWw+DQo8aHRtbCBsYW5nPSJlbiI+DQoJ...`;
            let _URL;
            switch (dest) {
                case "qq"       : _URL = qqBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";     break;
                case "weibo"    : _URL = weiboBase+"url="+hostUrl+"&title="+title+excerpt;                                 break;
                case "qzone"    : _URL = qzoneBase+"url="+hostUrl+"&title="+title+"&desc=&summary="+excerpt+"&site=cxpy";  break;
                case "facebook" : _URL = facebookBase+"u="+hostUrl;                                                        break;
                case "twitter"  : _URL = twitterBase+"text="+title+excerpt+"&url="+hostUrl;                                break;
            }
            window.open(_URL);
        };
    </script>
</div>
                
                </div>
            
            <div class="footer-tag clearfix">
                <div class="pull-left">
                <i class="fa fa-tags"></i>
                    <a class="tag-none-link" href="/tags/%E5%B7%A5%E5%85%B7/" rel="tag">工具</a>
                </div>
                <div class="pull-date">
                    <time datetime="2024-12-16T11:07:04.234Z" itemprop="dateModified">最后编辑：2024-12-16</time>
                </div>
            </div>
        </footer>
    </div>
    
        <nav class="navigation post-navigation clearfix" role="navigation">
            
            <div class="nav-previous clearfix">
                <a title=" Node自动发布到测试服务器替换目录文件" href="/2023/04/26/Node自动发布到测试服务器替换目录文件/">&lt; 上一篇</a>
            </div>
            
            
            <div class="nav-next clearfix">
                <a title=" html拖拽排序" href="/2023/06/30/html拖拽排序/">下一篇 &gt;</a>
            </div>
            
        </nav>
    
    
</article>

        

            </section>

        

                
            

<section id="kratos-widget-area" class="col-md-4 hidden-xs hidden-sm">
    <!-- 文章和页面根据splitter来分割，没有的话就从头开始设置为sticky -->
    
    
                <aside id="krw-about" class="widget widget-kratos-about clearfix">
    <div class="photo-background"></div>
    <div class="photo-wrapper clearfix">
        <div class="photo-wrapper-tip text-center">
            <img class="about-photo" src="/images/avatar.webp" loading="lazy" decoding="auto" />
        </div>
    </div>
    <div class="textwidget">
        <p class="text-center">孙刘森的博客</p>
    </div>
    <div class="site-meta">
        <a class="meta-item" href="/archives/">
            <span class="title">
                文章
            </span>
            <span class="count">
                34
            </span>
        </a>
        <a class="meta-item" href="/categories/">
            <span class="title">
                分类
            </span>
            <span class="count">
                11
            </span>
        </a>
        <a class="meta-item" href="/tags/">
            <span class="title">
                标签
            </span>
            <span class="count">
                18
            </span>
        </a>
    </div>
</aside>
            
                    <div class="sticky-area">
                
                
  <aside id="krw-categories" class="widget widget-kratos-categories clearfix">
    <h4 class="widget-title"><i class="fa fa-folder"></i>分类目录</h4>
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Js/">Js</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/PETS-3/">PETS-3</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Tools/">Tools</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/UniCloud/">UniCloud</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AD%99%E5%88%98%E6%A3%AE%E7%9A%84%E8%B4%A6%E6%9C%AC/">孙刘森的账本</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%89%E5%8D%93/">安卓</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%88%91%E7%9A%84%E5%8D%9A%E5%AE%A2/">我的博客</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/">排忧解难</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/%E7%A7%8D%E5%AD%90/">种子</a><span class="category-list-count">1</span></li></ul>
  </aside>


            
                
  <aside id="krw-tags" class="widget widget-kratos-tags clearfix">
    <h4 class="widget-title"><i class="fa fa-tags"></i>标签聚合</h4>
      <div class="tag-clouds">
        <a href="/tags/Docker/" style="font-size: 0.6em;">Docker</a> <a href="/tags/Java/" style="font-size: 0.6em;">Java</a> <a href="/tags/Linux/" style="font-size: 0.73em;">Linux</a> <a href="/tags/Mindway-js/" style="font-size: 0.6em;">Mindway.js</a> <a href="/tags/Mysql/" style="font-size: 0.6em;">Mysql</a> <a href="/tags/Nginx/" style="font-size: 0.67em;">Nginx</a> <a href="/tags/Node/" style="font-size: 0.6em;">Node</a> <a href="/tags/PETS-3/" style="font-size: 0.6em;">PETS-3</a> <a href="/tags/UniCloud/" style="font-size: 0.6em;">UniCloud</a> <a href="/tags/Vue3/" style="font-size: 0.6em;">Vue3</a> <a href="/tags/apk/" style="font-size: 0.6em;">apk</a> <a href="/tags/%E5%89%8D%E7%AB%AF/" style="font-size: 0.8em;">前端</a> <a href="/tags/%E5%89%8D%E7%AB%AF%E5%AD%98%E5%82%A8/" style="font-size: 0.6em;">前端存储</a> <a href="/tags/%E5%AD%99%E5%88%98%E6%A3%AE%E7%9A%84%E8%B4%A6%E6%9C%AC/" style="font-size: 0.6em;">孙刘森的账本</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 0.67em;">工具</a> <a href="/tags/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/" style="font-size: 0.6em;">排忧解难</a> <a href="/tags/%E7%A7%8D%E5%AD%90/" style="font-size: 0.6em;">种子</a> <a href="/tags/%E9%80%82%E9%85%8D/" style="font-size: 0.6em;">适配</a>
      </div>
  </aside>

            
                
  <aside id="krw-posts" class="widget widget-kratos-posts">
  <h4 class="widget-title"><i class="fa fa-file"></i>最新文章</h4>
  <div class="tab-content">
      <ul class="list-group">
        
        
          
          
            <a class="list-group-item" href="/2024/06/06/JS/%E9%80%82%E9%85%8D%E4%BB%A3%E7%A0%81/"><i class="fa  fa-book"></i> 前端rem适配代码</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/10/07/JS/canvas%E5%AE%9E%E7%8E%B0%E7%9B%96%E7%AB%A0/"><i class="fa  fa-book"></i> canvas实现盖章</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/08/31/JS/Js-sku%E5%95%86%E5%93%81%E8%A7%84%E5%88%99/"><i class="fa  fa-book"></i> Js-sku商品规则</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/07/28/%E6%8E%92%E5%BF%A7%E8%A7%A3%E9%9A%BE/"><i class="fa  fa-book"></i> 排忧解难</a>
            
          
        
          
          
            <a class="list-group-item" href="/2023/07/25/JS/Js%E5%AE%9E%E7%8E%B0%E8%A7%A3%E6%9E%90gif%E5%8A%A8%E5%9B%BE%E5%92%8C%E5%90%88%E6%88%90gif%E5%8A%A8%E5%9B%BE/"><i class="fa  fa-book"></i> Js实现解析gif动图和合成gif动图</a>
            
          
        
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
          
            
      </ul>
  </div>
  </aside>

            
    </div>
</section>
        
        </div>
    </div>
</div>
<footer>
    <div id="footer"  class="ap-lrc"  >
        <div class="container">
            <div class="row">
                <div class="col-md-6 col-md-offset-3 footer-list text-center">
                    <ul class="kratos-social-icons">
                        <!-- Keep for compatibility -->
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        <!-- New links -->
                        
                    </ul>
                    <ul class="kratos-copyright">
                        <div>
                            <li>&copy; 2024 Blog 版权所有.</li>
                            <li>本站已运行<span id="span_dt">Loading...</span></li>
                        </div>
                        <div>
                            <li>Theme <a href="https://github.com/Candinya/Kratos-Rebirth" target="_blank">Kratos:Rebirth</a></li>
                            <li>Site built with&nbsp;<i class="fa fa-heart throb" style="color:#d43f57"></i>&nbsp;by Sun Liusen.</li>
                        </div>
                        <div>
                            <li>Powered by <a href="https://hexo.io" target="_blank" rel="nofollow">Hexo</a></li>
                            <li>Hosted on <a href="https://github.io" target="_blank">Github Pages</a></li>
                        </div>
                        <div>
                            
                            
                        </div>
                    </ul>
                </div>
            </div>
        </div>
        <div class="kr-tool text-center">
            <div class="tool">
                
                    <div class="box search-box">
                        <a href="/search/">
                            <span class="fa fa-search"></span>
                        </a>
                    </div>
                
                
                    <div class="box theme-box" id="darkmode-switch">
                        <span class="fa fa-adjust"></span>
                    </div>
                
                
                
            </div>
            <div class="box gotop-box">
                <span class="fa fa-chevron-up"></span>
            </div>
        </div>
    </div>
</footer>
</div>
</div>

        <script defer src="/vendors/bootstrap@3.3.4/dist/js/bootstrap.min.js"></script>
<script defer src="/vendors/nprogress@0.2.0/nprogress.js"></script>
<script>
    if (!window.kr) {
        window.kr = {};
    }
    window.kr.notMobile = (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)));
    window.kr.siteRoot = "/";
</script>


    <script async src="/js/candy.min.js"></script>



    <script defer src="/vendors/aplayer@1.10.1/dist/APlayer.min.js"></script>
    
    <script defer src="/vendors/meting@2.0.1/dist/Meting.min.js"></script>
    <meting-js
        server="netease"
        type="playlist"
        id="3204190542"
        order="random"
        fixed="true"
    >
    </meting-js>



    <script defer src="/vendors/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

<script defer src="/js/kratosr.min.js"></script>
<script defer src="/js/pjax.min.js"></script>



<!-- Extra support for third-party plguins  -->


    </body>
</html>